package cn.smallran.novel.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.smallran.common.annotation.Log;
import cn.smallran.common.core.controller.BaseController;
import cn.smallran.common.core.domain.AjaxResult;
import cn.smallran.common.enums.BusinessType;
import cn.smallran.novel.domain.AuthorInfo;
import cn.smallran.novel.service.IAuthorInfoService;
import cn.smallran.common.utils.poi.ExcelUtil;
import cn.smallran.common.core.page.TableDataInfo;

/**
 * 作者信息Controller
 * 
 * @author smallran
 * @date 2024-12-01
 */
@RestController
@RequestMapping("/novel/authorInfo")
public class AuthorInfoController extends BaseController
{
    @Autowired
    private IAuthorInfoService authorInfoService;

    /**
     * 查询作者信息列表
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuthorInfo authorInfo)
    {
        startPage();
        List<AuthorInfo> list = authorInfoService.selectAuthorInfoList(authorInfo);
        return getDataTable(list);
    }

    /**
     * 导出作者信息列表
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:export')")
    @Log(title = "作者信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AuthorInfo authorInfo)
    {
        List<AuthorInfo> list = authorInfoService.selectAuthorInfoList(authorInfo);
        ExcelUtil<AuthorInfo> util = new ExcelUtil<AuthorInfo>(AuthorInfo.class);
        util.exportExcel(response, list, "作者信息数据");
    }

    /**
     * 获取作者信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(authorInfoService.selectAuthorInfoById(id));
    }

    /**
     * 新增作者信息
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:add')")
    @Log(title = "作者信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuthorInfo authorInfo)
    {
        return toAjax(authorInfoService.insertAuthorInfo(authorInfo));
    }

    /**
     * 修改作者信息
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:edit')")
    @Log(title = "作者信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuthorInfo authorInfo)
    {
        return toAjax(authorInfoService.updateAuthorInfo(authorInfo));
    }

    /**
     * 删除作者信息
     */
    @PreAuthorize("@ss.hasPermi('novel:authorInfo:remove')")
    @Log(title = "作者信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(authorInfoService.deleteAuthorInfoByIds(ids));
    }
}
